package com.woniuxy.backup;

import com.rabbitmq.client.*;
import com.woniuxy.utils.Utils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class BackConsume1 {
    public static void main(String[] args) throws IOException, TimeoutException {
        //声明一个连接对象
        Connection connection = Utils.getConnection();
        //创建一个对象
        Channel channel = connection.createChannel();
        //声明一个备用交换机
        channel.exchangeDeclare("backExchange", BuiltinExchangeType.DIRECT);
        //声明一个队列绑定到备用交换机上
        channel.queueDeclare("backQueue",false,false,false,null);
        channel.queueBind("backQueue","backExchange","back1");
        //消费者接受消息
        channel.basicConsume("backQueue",false,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("BackConsume1 接受消息："+new String(body));
                channel.basicAck(envelope.getDeliveryTag(),false);
            }
        });


    }
}
